home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / snpd1292.zip / STPTOK.C < prev    next >
C/C++ Source or Header  |  1992-12-26  |  1KB  |  38 lines

  1. /*
  2. **  stptok() -- public domain by Ray Gardner, modified by Bob Stout
  3. **
  4. **   You pass this function a string to parse, a buffer to receive the
  5. **   "token" that gets scanned, the length of the buffer, and a string of
  6. **   "break" characters that stop the scan.  It will copy the string into
  7. **   the buffer up to any of the break characters, or until the buffer is
  8. **   full, and will always leave the buffer null-terminated.  It will
  9. **   return a pointer to the first non-breaking character after the one
  10. **   that stopped the scan.
  11. */
  12.  
  13. #include <string.h>
  14.  
  15. char *stptok(const char *s, char *tok, size_t toklen, char *brk)
  16. {
  17.       char *lim, *b;
  18.  
  19.       if (!*s)
  20.             return NULL;
  21.  
  22.       lim = tok + toklen - 1;
  23.       while ( *s && tok < lim )
  24.       {
  25.             for ( b = brk; *b; b++ )
  26.             {
  27.                   if ( *s == *b )
  28.                   {
  29.                         *tok = 0;
  30.                         return s;
  31.                   }
  32.             }
  33.             *tok++ = *s++;
  34.       }
  35.       *tok = 0;
  36.       return s;
  37. }
  38.